package org.ruiyichen.guizhou.agr.bean.mode;

import org.ruiyichen.guizhou.agr.utils.L;
import org.ruiyichen.guizhou.agr.utils.StrUtil;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Comparator;
import java.util.Date;

public class AgileDeviceModel implements Comparable {

    private final static SimpleDateFormat format = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");

    public String deviceNumber;
    public String deviceName;
    public String irrigName;
    public String deviceType;
    public String macAddress;
    public String createTime;
    public String message;
    public String groupId;
    public String startTime;
    public String serialNumber;
    public String total;
    public String remainder;
    public String subtotal;
    public String modleNumber;
    public String settingPressure;
    public String soilTemperature;
    public String pumpState;
    public String messageCode;
    public String pressure;
    public String tensionValue;
    public String pumpType;
    public String deviceState;
    public String stopTime;
    public String recipe;
    public String deviceID;
    public String valveState;
    public String pumpSwitch;
    public String temperature;
    public String waterLevel;
    public String atmosphere;
    public String valveType;
    public String valveSwitch;
    public String windDirection;
    public String illuminance;
    public String script;
    public String soilMoisture;
    public String humidity;
    public String rainFall;
    public String windSpeed;
    public String waterTemperature;
    public String acidity;
    public String terminalType;
    public String systemClock;
    public String latitude;
    public String longitude;

    public String getHomeDeviceInfoStr() {
        //采集设备名称：
        //启动时间：
        //完成时间：
        //规格：
        //班组号：
        //模具号：
        StringBuilder sb = new StringBuilder();
        if (StrUtil.isNotEmpty(macAddress)) {
            sb.append("采集设备名称：").append(macAddress).append("\n");
        }
        if (StrUtil.isNotEmpty(startTime)) {
            sb.append("启动时间：").append(startTime).append("\n");
        }
        if (StrUtil.isNotEmpty(stopTime)) {
            sb.append("完成时间：").append(stopTime).append("\n");
        }
        if (StrUtil.isNotEmpty(recipe)) {
            sb.append("规格：").append(recipe).append("\n");
        }
        if (StrUtil.isNotEmpty(groupId)) {
            sb.append("班组号：").append(groupId).append("\n");
        }
        if (StrUtil.isNotEmpty(modleNumber)) {
            sb.append("模具号：").append(modleNumber);
        }
        return sb.toString();
    }

    public String getYearMonth() {
        //2020-06-11 06:12:13
        if (StrUtil.isNotEmpty(stopTime) && stopTime.length() > 7) {
            return stopTime.substring(0, 7);
        }
        return null;
    }

    @Override
    public int compareTo(Object o) {
        AgileDeviceModel t2 = (AgileDeviceModel) o;
        Date d1, d2;
        try {
            d1 = format.parse(this.stopTime);
            d2 = format.parse(t2.stopTime);
        } catch (ParseException e) {
            // 解析出错，则不进行排序
            L.e("wutian", "ComparatorDate--compare--SimpleDateFormat.parse--error");
            return 0;
        }
        if (d1.before(d2)) {
            return 1;
        } else {
            return -1;
        }
    }
}
